package com.ltx.vizflowservice.controller;

import com.ltx.vizflowservice.common.convention.result.Result;
import com.ltx.vizflowservice.common.convention.result.Results;
import com.ltx.vizflowservice.domain.dto.UserDTO;
import com.ltx.vizflowservice.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/*
 * @description 用户控制层
 * @author 罗添煦
 * @create 2024-11-14 下午11:17
 */
@RestController
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    /**
     * 登录
     *
     * @param userDTO 用户名密码
     * @return 登录结果，成功返回token
     */
    @PostMapping("/login")
    public Result<?> login(@RequestBody UserDTO userDTO) throws Exception {
        return userService.login(userDTO);
    }

    /**
     * 注册
     *
     * @param userDTO 用户名密码,确认密码
     * @return 注册结果
     */
    @PostMapping("/register")
    public Result<?> register(@RequestBody UserDTO userDTO) throws Exception {
        return userService.register(userDTO);
    }

    /**
     * 发送短信验证码
     * @param phone 手机号
     * @return 返回验证码
     */
    @GetMapping("/sms/send")
    public Result<?> send(@RequestParam("phone")String phone) {
        return userService.send(phone);
    }

    /**
     * 重置密码
     * @param userDTO 手机号、验证码、新密码
     * @return 重置密码结果
     */
    @PostMapping("/resetPassword")
    public Result<?> resetPassword(@RequestBody UserDTO userDTO) throws Exception {
        return userService.resetPassword(userDTO);
    }

    /**
     * 绑定手机号
     * @param userDTO 手机号、验证码、用户名
     * @return 绑定结果
     */
    @PostMapping("/bindPhone")
    public Result<?> bindPhone(@RequestBody UserDTO userDTO) throws Exception {
        return userService.bindPhone(userDTO);
    }
}
